package daos;
import com.j256.ormlite.dao.*;
import com.j256.ormlite.stmt.*;
import com.j256.ormlite.support.*;
import entities.*;
import java.util.*;
import java.util.logging.*;
import java.util.logging.Logger;

/**
 * This Class is used to handle 
 * the DAO methods of the VSecurityDao class 
 * @author Juanan JS  juanantonios@gmail.com
 */
public class VSecurityDao
{
    private ConnectionSource objConnectionSource=null;
    /**
     * Constructor:
     * @param objConnectionSource_ 
     * An active instance of a ConnectionSource
     */
    public VSecurityDao(ConnectionSource objConnectionSource_)
    {
        this.objConnectionSource=objConnectionSource_;
    }
    
    /**
     * @param strLogin String that represents a user the user Login Name
     * @return A List of access in VSecurity format of the Given Login Name
     * or null if the group doesn't exist
     */ 
    public List<VSecurity> findByLogin(String strLogin)
    {
        List<VSecurity> objUsrList =null;
        try
        {
            //JS: do the user dao
            Dao<VSecurity, String> objVSecurityDao = DaoManager.createDao(objConnectionSource, VSecurity.class);
            //JS: do the query for user login
            QueryBuilder<VSecurity, String> queryBuilder =objVSecurityDao.queryBuilder();
            queryBuilder.where().eq(VSecurity.USR_LOGIN, strLogin);
            PreparedQuery<VSecurity> preparedQuery = queryBuilder.prepare();
            //JS: query for all accounts that have that login
            objUsrList = objVSecurityDao.query(preparedQuery);
        } catch (Exception ex)
        {
            Logger.getLogger(UserDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        return objUsrList;
    }
}
